﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using carShop.Data.EntityFramework;
using carShop.Models;

namespace carShop.Data.Repositories.Custom
{
    public class UserRepository: Repository<User>
    {
        private UserStore<User> store;
        private UserManager<User> manager;

        public UserRepository(CarShopDbContext dbContext)
            : base(dbContext)
        {
            store = new UserStore<User>(dbContext);
            manager = new UserManager<User>(store);
        }

        public User GetByUsername(string username)
        {
            return manager.FindByName(username);
        }

        public void SetToken(string username,string password,string token)
        {

            var user = manager.Find(username, password);
            user.Token = token;
            manager.Update(user);
        }
    }
}